﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 资源加载缓存池，用于避免同样资源反复读取
/// </summary>
public class ResManager : MonoSingleton<ResManager> {

    Dictionary<string, Object> DicRes = new Dictionary<string, Object>();

    // 获取指定资源
    public Object GetRes(string path)
    {
        Object obj = null;
        if(DicRes.ContainsKey(path))
        {
            DicRes.TryGetValue(path,out obj);
        }
        else
        {
            obj = Resources.Load(path);
            DicRes.Add(path, obj);
        }
        return obj;
    }

    public Sprite LoadSourceSprite(string relativePath)
    {
        //Debug.Log("relativePath=" + relativePath);
        //把资源加载到内存中
        UnityEngine.Object Preb = Resources.Load(relativePath, typeof(Sprite));
        Sprite tmpsprite = null;
        try
        {
            tmpsprite = Instantiate(Preb) as Sprite;
        }
        catch (System.Exception ex)
        {

        }

        //用加载得到的资源对象，实例化游戏对象，实现游戏物体的动态加载
        return tmpsprite;
        //return Resources.Load(relativePath, typeof(Sprite)) as Sprite;
    }

   
    // 有多次使用可能的资源一次性定义并加载（只是单次使用的不需要在此定义字段）


    //春冬季主题的一般平台
    public Sprite[] gameTheme;
    //春季障碍物
    public Sprite[] springObstacle;
    //冬季障碍物
    public Sprite[] winterObstacle;
    //玩家皮肤
    public string[] skinName;
    public Sprite[] playerSkin;
    public Sprite[] playerControllerSkin;// 玩家控制角色游戏时的皮肤，而不是选择皮肤时的图片
    public GameObject playerSkinPerfab;// 玩家皮肤克隆生成，不需要放回对象池



    
}
